local assets = {
	Asset("ANIM", "anim/musha_apple.zip"),
	Asset("ANIM", "anim/musha_apple_cooked.zip"),
	Asset("ATLAS", "images/inventoryimages/musha_apple.xml"),
	Asset("IMAGE", "images/inventoryimages/musha_apple.tex"),
	Asset("ATLAS", "images/inventoryimages/musha_apple_cooked.xml"),
	Asset("IMAGE", "images/inventoryimages/musha_apple_cooked.tex")
}
local function musha_apple_oneaten(inst, eater)
	if eater.components.musha_staminasleep then
		eater.components.musha_staminasleep:DoDelta(5)
	end
	if eater.components.musha_fatiguesleep then
		eater.components.musha_fatiguesleep:DoDelta(-3)
	end
	if eater.components.musha_spellpower then
		eater.components.musha_spellpower:DoDelta(5)
	end
end

local function musha_apple_cooked_oneaten(inst, eater)
	if eater.components.musha_staminasleep then
		eater.components.musha_staminasleep:DoDelta(15)
	end
	if eater.components.musha_fatiguesleep then
		eater.components.musha_fatiguesleep:DoDelta(-7)
	end
	if eater.components.musha_spellpower then
		eater.components.musha_spellpower:DoDelta(8)
	end
end

AddIngredientValues({"musha_apple"}, {fruit = 1}, true)
AddIngredientValues({"musha_apple_cooked"}, {fruit = 1}, true)

local function fn(Sim)
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddSoundEmitter()
	inst.entity:AddNetwork()

	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("bulb")
	inst.AnimState:SetBuild("musha_apple")
	inst.AnimState:PlayAnimation("idle")
	inst:AddTag("cookable")
	inst.entity:SetPristine()
	if not TheWorld.ismastersim then
		return inst
	end

	inst.Transform:SetScale(0.7, 0.6, 0.7)
	inst:AddComponent("stackable")
	inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM

	inst:AddComponent("fuel")
	inst.components.fuel.fuelvalue = TUNING.MED_LARGE_FUEL
	inst.components.fuel.fueltype = "CAVE"

	inst:AddComponent("tradable")
	inst:AddComponent("edible")
	inst.components.edible.foodtype = FOODTYPE.GOODIES

	inst.components.edible.sanityvalue = 6
	inst.components.edible.healthvalue = 3
	inst.components.edible.hungervalue = 5
	inst.components.edible:SetOnEatenFn(musha_apple_oneaten)
	inst.components.edible.temperaturedelta = TUNING.COLD_FOOD_BONUS_TEMP
	inst.components.edible.temperatureduration = TUNING.FOOD_TEMP_BRIEF

	inst:AddComponent("perishable")
	inst.components.perishable:SetPerishTime(TUNING.PERISH_SLOW)
	inst.components.perishable:StartPerishing()
	inst.components.perishable.onperishreplacement = "spoiled_food"

	inst:AddComponent("inspectable")

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/musha_apple.xml"

	inst:AddComponent("cookable")
	inst.components.cookable.product = "musha_apple_cooked"

	return inst
end

local function fn_cooked()
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddSoundEmitter()
	inst.entity:AddNetwork()

	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("bulb")
	inst.AnimState:SetBuild("musha_apple_cooked")
	inst.AnimState:PlayAnimation("idle")
	inst.entity:SetPristine()
	if not TheWorld.ismastersim then
		return inst
	end

	inst.Transform:SetScale(0.7, 0.6, 0.7)
	inst:AddComponent("stackable")
	inst.components.stackable.maxsize = TUNING.STACK_SIZE_SMALLITEM

	inst:AddComponent("tradable")
	inst:AddComponent("edible")
	inst.components.edible.foodtype = FOODTYPE.GOODIES

	inst.components.edible.sanityvalue = 12
	inst.components.edible.healthvalue = 6
	inst.components.edible.hungervalue = 15
	inst.components.edible:SetOnEatenFn(musha_apple_cooked_oneaten)
	inst.components.edible.temperaturedelta = TUNING.COLD_FOOD_BONUS_TEMP
	inst.components.edible.temperatureduration = TUNING.FOOD_TEMP_BRIEF

	inst:AddComponent("perishable")
	inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
	inst.components.perishable:StartPerishing()
	inst.components.perishable.onperishreplacement = "spoiled_food"

	inst:AddComponent("inspectable")

	inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.atlasname = "images/inventoryimages/musha_apple_cooked.xml"

	return inst
end

-----------------

return Prefab("musha_apple", fn, assets), Prefab("musha_apple_cooked", fn_cooked, assets)
